// @ts-ignore
/* eslint-disable */
import request from '@/utils/request'

/** addAttache 添加附件 POST /api/attache/add */
export async function addAttacheUsingPost(
  body: {
    /** fileName */
    fileName: string
    /** type */
    type: number
    /** typeId */
    typeId: number
  },
  file?: File,
  options?: { [key: string]: any }
) {
  const formData = new FormData()

  if (file) {
    formData.append('file', file)
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as any)[ele]

    if (item !== undefined && item !== null) {
      if (typeof item === 'object' && !(item instanceof File)) {
        if (item instanceof Array) {
          item.forEach((f) => formData.append(ele, f || ''))
        } else {
          formData.append(ele, JSON.stringify(item))
        }
      } else {
        formData.append(ele, item)
      }
    }
  })

  return request<API.BaseResponseBoolean_>('/api/attache/add', {
    method: 'POST',
    data: formData,
    requestType: 'form',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    ...(options || {})
  })
}

/** deleteAttache 删除附件 DELETE /api/attache/delete */
export async function deleteAttacheUsingDelete(
  body: API.DeleteAttacheRequest,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponseBoolean_>('/api/attache/delete', {
    method: 'DELETE',
    headers: {
      'Content-Type': 'application/json'
    },
    data: body,
    ...(options || {})
  })
}

/** pageAttaches POST /api/attache/page */
export async function pageAttachesUsingPost(
  body: API.PageAttacheRequest,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponsePageAttachesVo_>('/api/attache/page', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    data: body,
    ...(options || {})
  })
}
